// Learn cc.Class:
//  - https://docs.cocos.com/creator/manual/en/scripting/class.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

cc.Class({
    extends: cc.Component,

    properties: {
        //音乐开关
        toggleMusic:cc.Toggle,
        //音效开关
        toggleSound:cc.Toggle,

    },

    onLoad () {
        this.toggleMusic.isChecked = window.gameConfig.gameData.isMusic == "0"? false:true;
        this.toggleSound.isChecked = window.gameConfig.gameData.isSound == "0"? false:true;
    },

    onClickMusic(){
        window.audioMgr.playGameAudio("buttonCheck");

        var musicState;
        var isOpen;
        if(window.gameConfig.gameData.isMusic == 1)musicState = 0;
        else musicState = 1;

        if(window.gameConfig.gameData.isOpen == 1)isOpen = 0;
        else isOpen = 1;

        window.gameConfig.saveGameData("isMusic", musicState);
        window.gameConfig.saveGameData("isOpen", isOpen);
        if(musicState == 1)
        {
            window.audioMgr.playGameAudio("music");
        }
        else
        {
            window.audioMgr.stopGameAudio("music");
        }
    },

    onClickSound(){
        window.audioMgr.playGameAudio("buttonCheck");

        var soundState;
        if(window.gameConfig.gameData.isSound == 1)soundState = 0;
        else soundState = 1;

        window.gameConfig.saveGameData("isSound", soundState);
    },

    closeLayer(event){
        window.audioMgr.playGameAudio("buttonCheck");
        event.interactable = false;
        window.closePop(this.node);
    }
});
